Completed
Push — master ( 576d64...22e707 )
by Sander
01:42 queued 33s
created

angular.controller(ꞌMainCtrlꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 21
rs 9.3142
1
/* global API */
2
3
/**
4
 * Nextcloud - passman
5
 *
6
 * @copyright Copyright (c) 2016, Sander Brand ([email protected])
7
 * @copyright Copyright (c) 2016, Marcos Zuriaga Miguel ([email protected])
8
 * @license GNU AGPL version 3 or any later version
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License as
12
 * published by the Free Software Foundation, either version 3 of the
13
 * License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 */
24
25
(function () {
26
    'use strict';
27
28
    /**
29
     * @ngdoc function
30
     * @name passmanApp.controller:MainCtrl
31
     * @description
32
     * # MainCtrl
33
     * Controller of the passmanApp
34
     */
35
    angular.module('passmanExtension')
36
        .controller('MainCtrl', ['$scope', '$mdSidenav', '$rootScope', function ($scope,  $mdSidenav, $rootScope) {
37
            function buildToggler(navID) {
38
                return function() {
39
                    // Component lookup should always be available since we are not using `ng-if`
40
                    $mdSidenav(navID)
41
                        .toggle();
42
                };
43
            }
44
45
            $scope.toolbarShown = true;
46
47
            $rootScope.$on('lockExtension', function () {
48
                $scope.lockExtension();
49
            });
50
51
            $rootScope.$on('unlocked', function () {
52
                $scope.toolbarShown = true;
53
            });
54
55
            $scope.toggleLeft = buildToggler('left');
56
57
            $scope.lockExtension = function () {
58
                $scope.toolbarShown = false;
59
                API.runtime.sendMessage(API.runtime.id, {method: "setMasterPassword", args: {password: null}}).then(function () {
60
                    window.location = '#!/locked';
61
                });
62
            };
63
64
            $scope.goto_list = function () {
65
                window.location = '#!/';
66
                $mdSidenav('left').close();
67
            };
68
            $scope.goto_settings = function () {
69
                window.location = '#!/settings';
70
                $mdSidenav('left').close();
71
            };
72
73
            $scope.goto_search = function () {
74
                window.location = '#!/search';
75
                $mdSidenav('left').close();
76
            };
77
78
            API.runtime.sendMessage(API.runtime.id, {'method': 'getRuntimeSettings'}).then(function (settings) {
79
                $rootScope.app_settings = settings;
80
                if (!settings || Object.keys(settings).length === 0) {
81
                    window.location = '#!/setup';
82
                } else if (settings.hasOwnProperty('isInstalled')) {
83
                    $scope.lockExtension();
84
                }
85
            });
86
87
        }]);
88
}());
89
90